#include <bits/stdc++.h>
using namespace std;
constexpr int MAXN = 200005;
int n, m, q, L[MAXN], R[MAXN]; vector<pair<int, int>> To[MAXN];
uint64_t F[MAXN], A[MAXN]; bool Vis[MAXN];
mt19937_64 rnd(time(nullptr));
void BFS(int s){
  queue<int> Q; Q.push(s);
  while(!Q.empty()){
    int id = Q.front(); Q.pop();
    if(Vis[id]) continue; else Vis[id] = 1;
    vector<pair<int, int>> Tmp;
    for(auto [nxt, e]: To[id]) if(!Vis[nxt]) Tmp.emplace_back(nxt, e), Q.push(nxt);
    if(!Tmp.empty()) F[Tmp[0].second] = A[id];
    for(size_t i = 1; i < Tmp.size(); i++) F[Tmp[0].second] ^= F[Tmp[i].second] = rnd();
    for(size_t i = 0; i < Tmp.size(); i++) A[id] ^= F[Tmp[i].second], A[Tmp[i].first] ^= F[Tmp[i].second];
  }
}
void DFS(int id){
  Vis[id] = 1;
  for(auto [nxt, e]: To[id]) if(!Vis[nxt])
    DFS(nxt), F[e] ^= A[nxt], A[id] ^= A[nxt], A[nxt] ^= A[nxt];
}
struct linear_base{
  uint64_t a[64];
  linear_base(){clear();}
  void clear(){memset(a, 0, sizeof(a));}
  bool insert(uint64_t x){
    for(int i = 63; i >= 0; i--) if(x >> i & 1){
      if(!a[i]){a[i] = x; return 1;} else x ^= a[i];
    } return 0;
  }
} LB;
int main(){
  freopen("graph.in", "r", stdin);
  freopen("graph.out", "w", stdout);
  cin.tie(nullptr)->sync_with_stdio(false);
  cin >> n >> m;
  for(int i = 1; i <= m; i++){
    cin >> L[i] >> R[i];
    To[L[i]].emplace_back(R[i], i);
    To[R[i]].emplace_back(L[i], i);
  }
  BFS(1), memset(Vis, 0, sizeof(Vis)), DFS(1);
  cin >> q;
  for(int _ = 1; _ <= q; _++){
    LB.clear(); bool Ans = 1;
    int x; cin >> x; while(x--){int y; cin >> y, Ans &= LB.insert(F[y]);}
    cout << (Ans? "YES\n": "NO\n");
  }
  cerr << (double)clock() / CLOCKS_PER_SEC << endl;
  return 0;
}
